**************************************** Table 1 ****************************************
cap file close fh


file open fh using "tables-and-figures/table1.tex", write replace

cap program drop comparesamples
program define comparesamples
** ALP complete 1 in 2013 
 use "$dir/data/outputs/ALP-HHbox-demographics", clear
 rename age1 d_age18to44
  rename age6 d_age65plus
  rename black africanamer
  rename ed_hi highschool
  rename ed_col college 
 summ `1' if complete ==1, detail
 local _temp_mean1=string(r(mean),"%04.2f")
 local _temp_sd1=string(r(sd),"%04.2f")
** ALP complete 2, in 2013 
 summ `1' if complete2==1, detail
 local _temp_mean2=string(r(mean),"%04.2f")
 local _temp_sd2=string(r(sd),"%04.2f")
 ** ALP all 2013
  summ `1', detail
 local _temp_mean4=string(r(mean),"%04.2f")
 local _temp_sd4=string(r(sd),"%04.2f")
** ALP complete 2, in 2016 
 use "$dir/data/outputs/ALP2demographics", clear
 summ `1' if complete==1, detail
 local _temp_mean3=string(r(mean),"%04.2f")
 local _temp_sd3=string(r(sd),"%04.2f")
** ALP all in 2016 
 summ `1', detail
 local _temp_mean5=string(r(mean),"%04.2f")
 local _temp_sd5=string(r(sd),"%04.2f")
** US adults in 2012 
 use "$dir/data/outputs/acs2012_2016adults.dta", clear
 sum `1' if year ==2012 [fweight=perwt]
 local _temp_meanACS=string(r(mean),"%04.2f")
 ** US adults in 2016 
 sum `1' if year ==2016 [fweight=perwt]
 local _temp_meanACS16=string(r(mean),"%04.2f")
 file write `3' "`2' & `_temp_mean1' & `_temp_mean2' & `_temp_mean3' & `_temp_mean4' & `_temp_mean5' & `_temp_meanACS' & `_temp_meanACS16' \\ [0.8em]  " _newline 
 *file write `3' " & (`_temp_sd1') & (`_temp_sd2') & (`_temp_sd3') & (`_temp_sd4') & . \\ " _newline 
end


comparesamples female "Female" fh
comparesamples age "Age" fh
comparesamples d_age18to44 "18 to 44 years old" fh
comparesamples d_age65plus "At least 65 years old" fh

comparesamples nonhispwhite "Caucasian (including Hispanics)" fh
comparesamples africanamer "African American" fh
comparesamples latino "Hispanic or Latino" fh

comparesamples highschool "High school diploma" fh
comparesamples college "College degree" fh

comparesamples approxincome "HH Income (in tsd)" fh

comparesamples employed "Currently employed" fh
comparesamples unemployed "Currently unemployed" fh
comparesamples outoflaborforce "Out of labor force" fh

comparesamples thenortheast "Lives in northeast (census region I)" fh
comparesamples themidwest "Lives in midwest (census region II)" fh
comparesamples thesouth "Lives in south (census region III)" fh
comparesamples thewest "Lives in west (census region IV)" fh

file close fh
